import TileLayer from "@arcgis/core/layers/TileLayer";
import Map from "@arcgis/core/Map";
import Ground from "@arcgis/core/Ground";
import ElevationLayer from "@arcgis/core/layers/ElevationLayer";
import Basemap from "@arcgis/core/Basemap";
import WebTileLayer from "@arcgis/core/layers/WebTileLayer";
import MapImageLayer from "@arcgis/core/layers/MapImageLayer";
import FeatureLayer from "@arcgis/core/layers/FeatureLayer";
import TileInfo from "@arcgis/core/layers/support/TileInfo";
import ScaleBar from "@arcgis/core/widgets/ScaleBar";
import Search from "@arcgis/core/widgets/Search";
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
import AttachmentsContent from "@arcgis/core/popup/content/AttachmentsContent";
import FieldInfo from "@arcgis/core/popup/FieldInfo";
import FieldsContent from "@arcgis/core/popup/content/FieldsContent";
import ImageMediaInfo from "@arcgis/core/popup/content/ImageMediaInfo";
import ImageMediaInfoValue from "@arcgis/core/popup/content/support/ImageMediaInfoValue";
import MediaContent from "@arcgis/core/popup/content/MediaContent";
import AttachmentQuery from "@arcgis/core/rest/support/AttachmentQuery";
/**
 * @description: 根据传入的图层名称调取配置文件创建图层
 * @param {*} layerName
 * @return {*}
 */
export function createLayer(layerName, dataScope, visible) {
  console.log("add layers");
  let layer = undefined;
  layer = new FeatureLayer({
    title: window.mapConfig.operationLayers.mapservers[layerName].title,
    url: window.mapConfig.operationLayers.mapservers[layerName].url,
    id: window.mapConfig.operationLayers.mapservers[layerName].id,
    opacity: window.mapConfig.operationLayers.mapservers[layerName].opacity,
    popupEnabled:
      window.mapConfig.operationLayers.mapservers[layerName].popupEnabled,
    visible:
      visible != undefined
        ? visible
        : window.mapConfig.operationLayers.mapservers[layerName].visible,
    outFields: mapConfig.operationLayers.mapservers[layerName].outFields,
    minScale: window.mapConfig.operationLayers.mapservers[layerName].minScale,
    maxScale: window.mapConfig.operationLayers.mapservers[layerName].maxScale,
    labelingInfo: mapConfig.operationLayers.mapservers[layerName].labels,
    definitionExpression: dataScope,
  });
  // 符号
  if (mapConfig.operationLayers.mapservers[layerName].renderer != undefined)
    layer.renderer = mapConfig.operationLayers.mapservers[layerName].renderer;
  return layer;
}
// export function createLayer(layerName) {
//   let layer = undefined;
//   switch (layerName) {
//     case "gusmmlayer":
//       layer = new FeatureLayer({
//         title:
//           window.mapConfig.operationLayers.featurelayers["gusmm"].title,
//         url: window.mapConfig.operationLayers.featurelayers["gusmm"].url,
//         id: window.mapConfig.operationLayers.featurelayers["gusmm"].id,
//         opacity:
//           window.mapConfig.operationLayers.featurelayers["gusmm"].opacity,
//         popupEnabled:
//           window.mapConfig.operationLayers.featurelayers["gusmm"].popupEnabled,
//         visible:
//           window.mapConfig.operationLayers.featurelayers["gusmm"].visible,
//         minScale:
//           window.mapConfig.operationLayers.featurelayers["gusmm"].minScale,
//         maxScale:
//           window.mapConfig.operationLayers.featurelayers["gusmm"].maxScale,
//         outFields: ["objectid"],
//       });
//       break;
//     case "dianzldlayer":
//       layer = new FeatureLayer({
//         title:
//           window.mapConfig.operationLayers.featurelayers["dianzld"]
//             .title,
//         url: window.mapConfig.operationLayers.featurelayers["dianzld"]
//           .url,
//         id: window.mapConfig.operationLayers.featurelayers["dianzld"]
//           .id,
//         opacity:
//           window.mapConfig.operationLayers.featurelayers["dianzld"]
//             .opacity,
//         popupEnabled:
//           window.mapConfig.operationLayers.featurelayers["dianzld"]
//             .popupEnabled,
//         visible:
//           window.mapConfig.operationLayers.featurelayers["dianzld"]
//             .visible,
//         minScale:
//           window.mapConfig.operationLayers.featurelayers["dianzld"]
//             .minScale,
//         maxScale:
//           window.mapConfig.operationLayers.featurelayers["dianzld"]
//             .maxScale,
//         outFields: ["objectid"],
//       });
//       break;
//     case "qitaldlayer":
//       layer = new FeatureLayer({
//         title:
//           window.mapConfig.operationLayers.featurelayers["qitald"]
//             .title,
//         url: window.mapConfig.operationLayers.featurelayers["qitald"]
//           .url,
//         id: window.mapConfig.operationLayers.featurelayers["qitald"]
//           .id,
//         opacity:
//           window.mapConfig.operationLayers.featurelayers["qitald"]
//             .opacity,
//         popupEnabled:
//           window.mapConfig.operationLayers.featurelayers["qitald"]
//             .popupEnabled,
//         visible:
//           window.mapConfig.operationLayers.featurelayers["qitald"]
//             .visible,
//         minScale:
//           window.mapConfig.operationLayers.featurelayers["qitald"]
//             .minScale,
//         maxScale:
//           window.mapConfig.operationLayers.featurelayers["qitald"]
//             .maxScale,
//         outFields: ["objectid"],
//       });
//     break;
//     case "roadldlayer":
//       layer = new FeatureLayer({
//         title:
//           window.mapConfig.operationLayers.featurelayers["roadld"]
//             .title,
//         url: window.mapConfig.operationLayers.featurelayers["roadld"]
//           .url,
//         id: window.mapConfig.operationLayers.featurelayers["roadld"]
//           .id,
//         opacity:
//           window.mapConfig.operationLayers.featurelayers["roadld"]
//             .opacity,
//         popupEnabled:
//           window.mapConfig.operationLayers.featurelayers["roadld"]
//             .popupEnabled,
//         visible:
//           window.mapConfig.operationLayers.featurelayers["roadld"]
//             .visible,
//         minScale:
//           window.mapConfig.operationLayers.featurelayers["roadld"]
//             .minScale,
//         maxScale:
//           window.mapConfig.operationLayers.featurelayers["roadld"]
//             .maxScale,
//         outFields: ["objectid"],
//       });
//     break;
//     case "xzqhlayer":
//       // layer = new MapImageLayer({
//       //   title: window.mapConfig.operationLayers.mapservers["xzqhlayer"].title,
//       //   url: window.mapConfig.operationLayers.mapservers["xzqhlayer"].url,
//       //   id: window.mapConfig.operationLayers.mapservers["xzqhlayer"].id,
//       //   // opacity: window.mapConfig.operationLayers.mapservers["shequ"].opacity,
//       //   // popupEnabled:
//       //   //   window.mapConfig.operationLayers.mapservers["shequ"].popupEnabled,
//       //   // visible: window.mapConfig.operationLayers.mapservers["shequ"].visible,
//       // });
//       layer = new FeatureLayer({
//         title:
//           window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//             .title,
//         url: window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//           .url,
//         id: window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//           .id,
//         opacity:
//           window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//             .opacity,
//         popupEnabled:
//           window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//             .popupEnabled,
//         visible:
//           window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//             .visible,
//         minScale:
//           window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//             .minScale,
//         maxScale:
//           window.mapConfig.operationLayers.featurelayers["xzqhlayer"]
//             .maxScale,
//       });

//     break;
//     // case "xzqh":
//     //   new FeatureLayer({
//     //     url: window.mapConfig.xzqhLayer.url,
//     //     id: window.mapConfig.xzqhLayer.id,
//     //     // opacity: window.mapConfig.operationLayers.mapservers["shequ"].opacity,
//     //     // popupEnabled:
//     //     //   window.mapConfig.operationLayers.mapservers["shequ"].popupEnabled,
//     //     // visible: window.mapConfig.operationLayers.mapservers["shequ"].visible,
//     //     symbol: window.mapConfig.xzqhLayer.symbol,
//     //   });
//     // break;
//     case "citykfbj":
//       layer = new FeatureLayer({
//         title: window.mapConfig.operationLayers.mapservers["citykfbj"].title,
//         url: window.mapConfig.operationLayers.mapservers["citykfbj"].url,
//         id: window.mapConfig.operationLayers.mapservers["citykfbj"].id,
//       });
//     break;
//     default:
//       layer = new MapImageLayer({
//         title: window.mapConfig.operationLayers.mapservers["gusmmlayer"].title,
//         url: window.mapConfig.operationLayers.mapservers["gusmmlayer"].url,
//         id: window.mapConfig.operationLayers.mapservers["gusmmlayer"].id,
//         // opacity: window.mapConfig.operationLayers.roadlayer["dianzld"].opacity,
//         // popupEnabled:
//         //   window.mapConfig.operationLayers.mapservers["dianzld"].popupEnabled,
//         // visible: window.mapConfig.operationLayers.mapservers["dianzld"].visible,
//       });
//       break;
//   }
//   return layer;
// }
/**
 * @description: 设定点状绿地弹窗口内容
 * @param {*} feature
 * @return {*}
 */
export async function setDianzldPopContent(feature) {
  console.log(feature);
  let fieldInfo1 = new FieldInfo({
    fieldName: "objcode", // using a related table's field
    label: "标识码",
    visible: true,
  });
  let fieldInfo2 = new FieldInfo({
    fieldName: "objname",
    label: "名称",
    visible: true,
  });
  let fieldInfo3 = new FieldInfo({
    fieldName: "type",
    label: "绿地大类",
    visible: true,
  });
  let fieldInfo4 = new FieldInfo({
    fieldName: "type_m",
    label: "绿地中类",
    visible: true,
  });
  let fieldInfo5 = new FieldInfo({
    fieldName: "type_s",
    label: "绿地小类",
    visible: true,
  });
  let fieldInfo6 = new FieldInfo({
    fieldName: "suosxzq",
    label: "所属行政区",
    visible: true,
  });
  let fieldInfo7 = new FieldInfo({
    fieldName: "suosjd",
    label: "所属街道",
    visible: true,
  });
  let fieldInfo8 = new FieldInfo({
    fieldName: "suossq",
    label: "所属社区",
    visible: true,
  });
  let fieldInfo9 = new FieldInfo({
    fieldName: "zhandmj",
    label: "占地面积",
    visible: true,
  });
  let fieldInf10 = new FieldInfo({
    fieldName: "deptname",
    label: "主管部门",
    visible: true,
  });
  let fieldInf11 = new FieldInfo({
    fieldName: "qsmcname",
    label: "权属单位",
    visible: true,
  });
  let fieldInf12 = new FieldInfo({
    fieldName: "yhmcname",
    label: "养护单位",
    visible: true,
  });
  let fieldInf13 = new FieldInfo({
    fieldName: "treenum",
    label: "树种",
    visible: true,
  });
  let fieldInf14 = new FieldInfo({
    fieldName: "dist",
    label: "胸径",
    visible: true,
  });
  let fieldInf15 = new FieldInfo({
    fieldName: "collectdate",
    label: "采集日期",
    visible: true,
  });
  let fieldInf16 = new FieldInfo({
    fieldName: "updatedate",
    label: "更新日期",
    visible: true,
  });
  let fieldInf17 = new FieldInfo({
    fieldName: "datasource",
    label: "数据来源",
    visible: true,
  });
  let fieldInf18 = new FieldInfo({
    fieldName: "note",
    label: "备注",
    visible: true,
  });
  // Create the FieldsContent element
  let fieldsElement = new FieldsContent({
    fieldInfos: [
      fieldInfo1,
      fieldInfo2,
      fieldInfo3,
      fieldInfo4,
      fieldInfo5,
      fieldInfo6,
      fieldInfo7,
      fieldInfo8,
      fieldInfo9,
      fieldInf10,
      fieldInf11,
      fieldInf12,
      fieldInf13,
      fieldInf14,
      fieldInf15,
      fieldInf16,
      fieldInf17,
      fieldInf18,
    ],
  });
  const attachmentsElement = new AttachmentsContent({
    displayType: "list",
  });

  let mediaElement = undefined;
  let imageElements = [];
  let imageElement = undefined;
  let imageMediaInfoValue = undefined;
  const objectid = feature.graphic.attributes.objectid;
  const layer = feature.graphic.sourceLayer;
  const attachmentQuery = new AttachmentQuery({
    objectIds: [objectid],
    // attachmentsWhere: `objectid = ${objectid}` // attachment queries
  });
  const attachments = await layer.queryAttachments(attachmentQuery);
  if (attachments[objectid]) {
    let attachment = attachments[objectid];
    attachment.forEach((item) => {
      // Create the ImageMediaInfoValue
      imageMediaInfoValue = new ImageMediaInfoValue({
        sourceURL: item.url,
      });
      // Create the ImageMediaInfo
      imageElement = new ImageMediaInfo({
        value: imageMediaInfoValue,
      });

      imageElements.push(imageElement);
    });
    mediaElement = new MediaContent({
      mediaInfos: imageElements,
    });
  }

  // let imageMediaInfoValue1 = new ImageMediaInfoValue({
  //   sourceURL:
  //     "http://vm.wskcy.cn/server/rest/services/midong/ldpc/FeatureServer/4/5/attachments/135",
  // });

  // Create the ImageMediaInfo
  // let imageElement1 = new ImageMediaInfo({
  //   // title: "<b>Mexican Fan Palm</b>",
  //   // caption: "tree species",
  //   value: imageMediaInfoValue1,
  // });
  // let imageMediaInfoValue2 = new ImageMediaInfoValue({
  //   sourceURL:
  //     "https://vm.wskcy.cn/server/rest/services/midong/ldpc/MapServer/5/1/attachments/4200",
  // });

  // // Create the ImageMediaInfo
  // let imageElement2 = new ImageMediaInfo({
  //   // title: "<b>Mexican Fan Palm</b>",
  //   // caption: "tree species",
  //   value: imageMediaInfoValue2,
  // });
  // imageElements.push(imageElement1);
  // imageElements.push(imageElement2);
  // // Create the MediaContent
  //  mediaElement = new MediaContent({
  //   mediaInfos: imageElements,
  // });
  // const mediaElement1 = new MediaContent({
  //   // Autocasts as new MediaContent()
  //   type: "media",
  //   mediaInfos: [
  //     {
  //       type: "image", // Autocasts as new ImageMediaInfo()
  //       // Autocasts as new ImageMediaInfoValue()
  //       value: {
  //         sourceURL:
  //           "http://vm.wskcy.cn/server/rest/services/midong/ldpc/FeatureServer/4/5/attachments/135",
  //       },
  //     },
  //     {
  //       type: "image", // Autocasts as new ImageMediaInfo()
  //       // Autocasts as new ImageMediaInfoValue()
  //       value: {
  //         sourceURL:
  //           "https://vm.wskcy.cn/server/rest/services/midong/ldpc/MapServer/5/1/attachments/4200",
  //       },
  //     },
  //   ],
  // });
  if (mediaElement != undefined) return [fieldsElement, mediaElement];
  else return [fieldsElement];
}

export async function setRoadldPopContent(feature) {
  console.log(feature);
  let fieldInfo1 = new FieldInfo({
    fieldName: "objcode", // using a related table's field
    label: "标识码",
    visible: true,
  });
  let fieldInfo2 = new FieldInfo({
    fieldName: "objname",
    label: "名称",
    visible: true,
  });
  let fieldInfo3 = new FieldInfo({
    fieldName: "type",
    label: "绿地大类",
    visible: true,
  });
  let fieldInfo4 = new FieldInfo({
    fieldName: "type_m",
    label: "绿地中类",
    visible: true,
  });
  let fieldInfo5 = new FieldInfo({
    fieldName: "type_s",
    label: "绿地小类",
    visible: true,
  });
  let fieldInfo6 = new FieldInfo({
    fieldName: "suosxzq",
    label: "所属行政区",
    visible: true,
  });
  let fieldInfo7 = new FieldInfo({
    fieldName: "suosjd",
    label: "所属街道",
    visible: true,
  });
  let fieldInfo8 = new FieldInfo({
    fieldName: "suossq",
    label: "所属社区",
    visible: true,
  });
  let fieldInfo9 = new FieldInfo({
    fieldName: "zhandmj",
    label: "占地面积",
    visible: true,
  });
  let fieldInf10 = new FieldInfo({
    fieldName: "deptname",
    label: "主管部门",
    visible: true,
  });
  let fieldInf11 = new FieldInfo({
    fieldName: "qsmcname",
    label: "权属单位",
    visible: true,
  });
  let fieldInf12 = new FieldInfo({
    fieldName: "yhmcname",
    label: "养护单位",
    visible: true,
  });
  let fieldInf13 = new FieldInfo({
    fieldName: "lvdmxz",
    label: "绿地面现状",
    visible: true,
  });
  let fieldInf14 = new FieldInfo({
    fieldName: "collectdate",
    label: "采集日期",
    visible: true,
  });
  let fieldInf15 = new FieldInfo({
    fieldName: "updatedate",
    label: "更新日期",
    visible: true,
  });
  let fieldInf16 = new FieldInfo({
    fieldName: "datasource",
    label: "数据来源",
    visible: true,
  });
  let fieldInf17 = new FieldInfo({
    fieldName: "treenum1",
    label: "第一树种",
    visible: true,
  });
  let fieldInf18 = new FieldInfo({
    fieldName: "treenum1_s",
    label: "第一树种数量",
    visible: true,
  });
  let fieldInf19 = new FieldInfo({
    fieldName: "treenum2",
    label: "第二树种数量",
    visible: true,
  });
  let fieldInf20 = new FieldInfo({
    fieldName: "treenum2_s",
    label: "第二树种数量",
    visible: true,
  });
  let fieldInf21 = new FieldInfo({
    fieldName: "treenum3",
    label: "第三树种",
    visible: true,
  });
  let fieldInf22 = new FieldInfo({
    fieldName: "treenum3_s",
    label: "第三树种数量",
    visible: true,
  });
  let fieldInf23 = new FieldInfo({
    fieldName: "treenum4",
    label: "第四树种",
    visible: true,
  });
  let fieldInf24 = new FieldInfo({
    fieldName: "treenum4_s",
    label: "第四树种数量",
    visible: true,
  });
  let fieldInf25 = new FieldInfo({
    fieldName: "treenum5",
    label: "第五树种",
    visible: true,
  });
  let fieldInf26 = new FieldInfo({
    fieldName: "treenum5_s",
    label: "第五树种数量",
    visible: true,
  });
  let fieldInf27 = new FieldInfo({
    fieldName: "treenum6",
    label: "第六树种",
    visible: true,
  });
  let fieldInf28 = new FieldInfo({
    fieldName: "treenum6_s",
    label: "第六树种数量",
    visible: true,
  });
  let fieldInf29 = new FieldInfo({
    fieldName: "treenum7",
    label: "第七树种",
    visible: true,
  });
  let fieldInf30 = new FieldInfo({
    fieldName: "treenum7_s",
    label: "第七树种数量",
    visible: true,
  });
  let fieldInf31 = new FieldInfo({
    fieldName: "treenum8",
    label: "第八树种",
    visible: true,
  });
  let fieldInf32 = new FieldInfo({
    fieldName: "treenum8_s",
    label: "第八树种数量",
    visible: true,
  });
  let fieldInf33 = new FieldInfo({
    fieldName: "treenum9",
    label: "第九树种",
    visible: true,
  });
  let fieldInf34 = new FieldInfo({
    fieldName: "treenum9_s",
    label: "第九树种数量",
    visible: true,
  });
  let fieldInf35 = new FieldInfo({
    fieldName: "treenum10",
    label: "第十树种",
    visible: true,
  });
  let fieldInf36 = new FieldInfo({
    fieldName: "treenum10_s",
    label: "第十树种数量",
    visible: true,
  });
  let fieldInf37 = new FieldInfo({
    fieldName: "treeqt",
    label: "其他树种",
    visible: true,
  });
  let fieldInf38 = new FieldInfo({
    fieldName: "treeqt_s",
    label: "其他树种数量",
    visible: true,
  });
  let fieldInf39 = new FieldInfo({
    fieldName: "treenum",
    label: "乔木总量",
    visible: true,
  });
  let fieldInf40 = new FieldInfo({
    fieldName: "dist",
    label: "胸径",
    visible: true,
  });
  let fieldInf41 = new FieldInfo({
    fieldName: "gmzlei",
    label: "灌木种类",
    visible: true,
  });
  let fieldInf42 = new FieldInfo({
    fieldName: "gmzb",
    label: "灌木占比",
    visible: true,
  });
  let fieldInf43 = new FieldInfo({
    fieldName: "guangms",
    label: "灌溉模式",
    visible: true,
  });
  let fieldInf44 = new FieldInfo({
    fieldName: "guangsy",
    label: "灌溉水源",
    visible: true,
  });
  let fieldInf45 = new FieldInfo({
    fieldName: "suozdlmc",
    label: "所在道路名称",
    visible: true,
  });
  let fieldInf46 = new FieldInfo({
    fieldName: "note",
    label: "备注",
    visible: true,
  });
  // Create the FieldsContent element
  let fieldsElement = new FieldsContent({
    fieldInfos: [
      fieldInfo1,
      fieldInfo2,
      fieldInfo3,
      fieldInfo4,
      fieldInfo5,
      fieldInfo6,
      fieldInfo7,
      fieldInfo8,
      fieldInfo9,
      fieldInf10,
      fieldInf11,
      fieldInf12,
      fieldInf13,
      fieldInf14,
      fieldInf15,
      fieldInf16,
      fieldInf17,
      fieldInf18,
      fieldInf19,
      fieldInf20,
      fieldInf21,
      fieldInf22,
      fieldInf23,
      fieldInf24,
      fieldInf25,
      fieldInf26,
      fieldInf27,
      fieldInf28,
      fieldInf29,
      fieldInf30,
      fieldInf31,
      fieldInf32,
      fieldInf33,
      fieldInf34,
      fieldInf35,
      fieldInf36,
      fieldInf37,
      fieldInf38,
      fieldInf39,
      fieldInf40,
      fieldInf41,
      fieldInf42,
      fieldInf43,
      fieldInf44,
      fieldInf45,
      fieldInf46,
    ],
  });
  const attachmentsElement = new AttachmentsContent({
    displayType: "list",
  });

  let mediaElement = undefined;
  let imageElements = [];
  let imageElement = undefined;
  let imageMediaInfoValue = undefined;
  const objectid = feature.graphic.attributes.objectid;
  const layer = feature.graphic.sourceLayer;
  const attachmentQuery = new AttachmentQuery({
    objectIds: [objectid],
    // attachmentsWhere: `objectid = ${objectid}` // attachment queries
  });
  const attachments = await layer.queryAttachments(attachmentQuery);
  if (attachments[objectid]) {
    let attachment = attachments[objectid];
    attachment.forEach((item) => {
      // Create the ImageMediaInfoValue
      imageMediaInfoValue = new ImageMediaInfoValue({
        sourceURL: item.url,
      });
      // Create the ImageMediaInfo
      imageElement = new ImageMediaInfo({
        value: imageMediaInfoValue,
      });

      imageElements.push(imageElement);
    });
    mediaElement = new MediaContent({
      mediaInfos: imageElements,
    });
  }

  if (mediaElement != undefined) return [fieldsElement, mediaElement];
  else return [fieldsElement];
}
export async function setQitaldPopContent(feature) {
  console.log(feature);
  let fieldInfo1 = new FieldInfo({
    fieldName: "objcode", // using a related table's field
    label: "标识码",
    visible: true,
  });
  let fieldInfo2 = new FieldInfo({
    fieldName: "objname",
    label: "名称",
    visible: true,
  });
  let fieldInfo3 = new FieldInfo({
    fieldName: "type",
    label: "绿地大类",
    visible: true,
  });
  let fieldInfo4 = new FieldInfo({
    fieldName: "type_m",
    label: "绿地中类",
    visible: true,
  });
  let fieldInfo5 = new FieldInfo({
    fieldName: "type_s",
    label: "绿地小类",
    visible: true,
  });
  let fieldInfo6 = new FieldInfo({
    fieldName: "suosxzq",
    label: "所属行政区",
    visible: true,
  });
  let fieldInfo7 = new FieldInfo({
    fieldName: "suosjd",
    label: "所属街道",
    visible: true,
  });
  let fieldInfo8 = new FieldInfo({
    fieldName: "suossq",
    label: "所属社区",
    visible: true,
  });
  let fieldInfo9 = new FieldInfo({
    fieldName: "zhandmj",
    label: "占地面积",
    visible: true,
  });
  let fieldInf10 = new FieldInfo({
    fieldName: "deptname",
    label: "主管部门",
    visible: true,
  });
  let fieldInf11 = new FieldInfo({
    fieldName: "qsmcname",
    label: "权属单位",
    visible: true,
  });
  let fieldInf12 = new FieldInfo({
    fieldName: "yhmcname",
    label: "养护单位",
    visible: true,
  });
  let fieldInf13 = new FieldInfo({
    fieldName: "lvdmxz",
    label: "绿地面现状",
    visible: true,
  });
  let fieldInf14 = new FieldInfo({
    fieldName: "collectdate",
    label: "采集日期",
    visible: true,
  });
  let fieldInf15 = new FieldInfo({
    fieldName: "updatedate",
    label: "更新日期",
    visible: true,
  });
  let fieldInf16 = new FieldInfo({
    fieldName: "datasource",
    label: "数据来源",
    visible: true,
  });
  let fieldInf17 = new FieldInfo({
    fieldName: "treenum1",
    label: "第一树种",
    visible: true,
  });
  let fieldInf18 = new FieldInfo({
    fieldName: "treenum2",
    label: "第二树种数量",
    visible: true,
  });
  let fieldInf19 = new FieldInfo({
    fieldName: "treenum3",
    label: "第三树种",
    visible: true,
  });
  let fieldInf20 = new FieldInfo({
    fieldName: "treenum4",
    label: "第四树种",
    visible: true,
  });
  let fieldInf21 = new FieldInfo({
    fieldName: "treenum5",
    label: "第五树种",
    visible: true,
  });
  let fieldInf22 = new FieldInfo({
    fieldName: "treenum6",
    label: "第六树种",
    visible: true,
  });
  let fieldInf23 = new FieldInfo({
    fieldName: "treenum7",
    label: "第七树种",
    visible: true,
  });
  let fieldInf24 = new FieldInfo({
    fieldName: "treenum8",
    label: "第八树种",
    visible: true,
  });
  let fieldInf25 = new FieldInfo({
    fieldName: "treenum9",
    label: "第九树种",
    visible: true,
  });
  let fieldInf26 = new FieldInfo({
    fieldName: "treenum10",
    label: "第十树种",
    visible: true,
  });
  let fieldInf27 = new FieldInfo({
    fieldName: "treeqt",
    label: "其他树种",
    visible: true,
  });
  let fieldInf28 = new FieldInfo({
    fieldName: "treenum",
    label: "乔木总量",
    visible: true,
  });
  let fieldInf29 = new FieldInfo({
    fieldName: "dist",
    label: "胸径",
    visible: true,
  });
  let fieldInf30 = new FieldInfo({
    fieldName: "gmzlei",
    label: "灌木种类",
    visible: true,
  });
  let fieldInf31 = new FieldInfo({
    fieldName: "gmzb",
    label: "灌木占比",
    visible: true,
  });
  let fieldInf32 = new FieldInfo({
    fieldName: "guangms",
    label: "灌溉模式",
    visible: true,
  });
  let fieldInf33 = new FieldInfo({
    fieldName: "guangsy",
    label: "灌溉水源",
    visible: true,
  });
  let fieldInf34 = new FieldInfo({
    fieldName: "note",
    label: "备注",
    visible: true,
  });
  // Create the FieldsContent element
  let fieldsElement = new FieldsContent({
    fieldInfos: [
      fieldInfo1,
      fieldInfo2,
      fieldInfo3,
      fieldInfo4,
      fieldInfo5,
      fieldInfo6,
      fieldInfo7,
      fieldInfo8,
      fieldInfo9,
      fieldInf10,
      fieldInf11,
      fieldInf12,
      fieldInf13,
      fieldInf14,
      fieldInf15,
      fieldInf16,
      fieldInf17,
      fieldInf18,
      fieldInf19,
      fieldInf20,
      fieldInf21,
      fieldInf22,
      fieldInf23,
      fieldInf24,
      fieldInf25,
      fieldInf26,
      fieldInf27,
      fieldInf28,
      fieldInf29,
      fieldInf30,
      fieldInf31,
      fieldInf32,
      fieldInf33,
      fieldInf34,
    ],
  });
  const attachmentsElement = new AttachmentsContent({
    displayType: "list",
  });

  let mediaElement = undefined;
  let imageElements = [];
  let imageElement = undefined;
  let imageMediaInfoValue = undefined;
  const objectid = feature.graphic.attributes.objectid;
  const layer = feature.graphic.sourceLayer;
  const attachmentQuery = new AttachmentQuery({
    objectIds: [objectid],
    // attachmentsWhere: `objectid = ${objectid}` // attachment queries
  });
  const attachments = await layer.queryAttachments(attachmentQuery);
  if (attachments[objectid]) {
    let attachment = attachments[objectid];
    attachment.forEach((item) => {
      // Create the ImageMediaInfoValue
      imageMediaInfoValue = new ImageMediaInfoValue({
        sourceURL: item.url,
      });
      // Create the ImageMediaInfo
      imageElement = new ImageMediaInfo({
        value: imageMediaInfoValue,
      });

      imageElements.push(imageElement);
    });
    mediaElement = new MediaContent({
      mediaInfos: imageElements,
    });
  }

  if (mediaElement != undefined) return [fieldsElement, mediaElement];
  else return [fieldsElement];
}
// 查询附件
async function getAttachment(layer, objectid) {
  let mediaInfos = [];

  console.log("objectid:" + objectid);
  const attachmentQuery = new AttachmentQuery({
    objectIds: [objectid],
    // attachmentsWhere: `objectid = ${objectid}` // attachment queries
  });
  const attachments = await layer.queryAttachments(attachmentQuery);
  if (attachments[objectid]) {
    let attachment = attachments[objectid];
    attachment.forEach((item) => {
      // Create the ImageMediaInfoValue
      let imageMediaInfoValue = new ImageMediaInfoValue({
        sourceURL: item.url,
      });

      // Create the ImageMediaInfo
      let imageElement = new ImageMediaInfo({
        // title: "<b>Mexican Fan Palm</b>",
        // caption: "tree species",
        value: imageMediaInfoValue,
      });

      mediaInfos.push(imageElement);
    });
    mediaElement = new MediaContent({ mediaInfos: mediaInfos });
    console.log(mediaElement);
    return mediaElement;
  }
  return mediaElement;
  // layer
  //   .queryAttachments(attachmentQuery)
  //   .then((attachments) => {
  //     console.log(attachments);
  //     if (attachments[objectid]) {
  //       let attachment = attachments[objectid];
  //       attachment.forEach((item) => {
  //         // Create the ImageMediaInfoValue
  //         let imageMediaInfoValue = new ImageMediaInfoValue({
  //           sourceURL: item.url,
  //         });

  //         // Create the ImageMediaInfo
  //         let imageElement = new ImageMediaInfo({
  //           // title: "<b>Mexican Fan Palm</b>",
  //           // caption: "tree species",
  //           value: imageMediaInfoValue,
  //         });

  //         mediaInfos.push(imageElement);
  //       });
  //       mediaElement = new MediaContent({ mediaInfos: mediaInfos });
  //       console.log(mediaElement);
  //       return mediaElement;
  //     }
  //   })
  //   .catch(function (error) {
  //     console.log("attachment query error", error);
  //   });
}
